//
//  MyInsyranceDetailViewController.m
//  shopping
//
//  Created by 马田成 on 2017/9/4.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "MyInsyranceDetailViewController.h"

@interface MyInsyranceDetailViewController ()

@end

@implementation MyInsyranceDetailViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initNavLeftBtn];
    UIWebView  *myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, scrWidth(), scrHeight())];
    //    myWebView.delegate = self;
    [self.view addSubview:myWebView];
    myWebView.backgroundColor = [UIColor whiteColor];
    NSString *basePath = [[NSBundle mainBundle]bundlePath];
    NSString *helpHtmlPath = [basePath stringByAppendingPathComponent:@"baoxian.html"];
    NSURL *url = [NSURL fileURLWithPath:helpHtmlPath];
    //加载本地html文件
    [myWebView loadRequest:[NSURLRequest requestWithURL:url]];
    // Do any additional setup after loading the view.
}
#pragma mark 初始化nav left
-(void)initNavLeftBtn{
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, screenScale(20), screenScale(20));
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"back_black"] forState:UIControlStateNormal];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"back_black"] forState:UIControlStateSelected];
    [leftBtn addTarget:self action:@selector(leftNavItemClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarBtn = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftBarBtn;
}

-(void)leftNavItemClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    
    /**
     
     <!-- 自定义协议与OC进行交互 -->
     
     // 网页上的一个链接，点击这个链接出发以下反应。。。
     
     <a href="protocol:///showMessage:/晚上小树林见">女神</a>
     
     */
    
    //在此方法中截取下一个请求的URL,通过自定义协议头，截取要执行的方法和参数
    
    if ([request.URL.scheme isEqualToString:@"protocol"]) {
        
        //调用oc的方法做事
        
        //工作中用下面的
        
        NSArray *pathComponents = [request.URL pathComponents];
        
        //获取到方法名的字符串
        
        NSString *methodName = pathComponents[1];
        
        //获取到的参数的字符串
        //
        //        NSString *param= pathComponents[2];
        
        //SEL
        
        SEL method = NSSelectorFromString(methodName);
        
        //调用方法
        
        if ([self respondsToSelector:method]) {
            
            [self performSelector:method];
            
        }
        
        return NO;
        
    }
    
    return YES;
    
}

// OC的方法

- (void)showMessage{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
